﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PerCederberg.Grammatica.Runtime;

namespace SafeScript.MetaModel
{
    public class MemberEvent : INamed, ITypeDef
    {
        public string Name { get; set; }
        public ITypeDef EventType;
        public Statements.Operator InitialValue;
        public Namespace Owner;
        public bool IsStatic;
        
        internal Node Node;
        internal Using Using;

        /// <summary>
        /// May be null.
        /// </summary>
        public MemberAttribute[] Attributes { get; set; }

        public MemberAttribute GetAttribute(string name)
        {
            if (this.Attributes == null)
                return null;
            foreach (MemberAttribute attr in this.Attributes)
            {
                if (attr.Name == name)
                    return attr;
            }
            return null;
        }

        #region ITypeDef Members

        public bool IsEqualTo(ITypeDef typedef)
        {
            return (typedef is MemberEvent) && (typedef as MemberEvent).EventType.IsEqualTo(this.EventType);
        }

        public bool CanBeAssignedTo(ITypeDef typedef)
        {
            return this.IsEqualTo(typedef);
        }

        public int GetInheritanceDepth(ITypeDef typedef)
        {
            return this.IsEqualTo(typedef) ? 0 : -1;
        }

        public ITypeDef Instantiate(Dictionary<TemplateParameterType, ITypeDef> templateArguments)
        {
            throw new NotImplementedException();
        }
        #endregion

    }
}
